<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>图书总览</title>

<!-- Bootstrap -->
<link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="<%=request.getContextPath() %>/css/common/common.css">
<link rel="stylesheet" href="<%=request.getContextPath() %>/css/easyui/easyui.css">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
    <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<%--     <img alt="图片" src="<%=request.getContextPath() %>/image/img1.png" /> --%>
<script>

</script>
<style type="text/css">
	
</style>
</head>

<body>
	<div class="container">
	<div class="row">
		<div class="page-header">
			<h1><small>已收录书籍</small></h1>
		</div>
		<div class="col-lg-12">
			<div class="col-lg-offset-9 col-md-offset-8 col-lg-3 col-md-4">
				<div class="input-group">
					<input id="bname" type="text" class="form-control" placeholder="查询书名">
					<span class="input-group-btn">
						<button class="btn btn-default" type="button" onclick="queryAll()">查询</button>
						<button class="btn btn-default" type="button" onclick="initQuery()">重置</button>
					</span>
				</div>
			</div>
		</div>
		<div class="col-lg-12" style="height: 10px">
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="" style="width: 100%; height: 500px;">
				<table id="allbookes"></table>
			</div>
		</div>
	</div>
	</div>
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script src="<%=request.getContextPath() %>/js/bootstrap/bootstrap.min.js"></script>
<script src="<%=request.getContextPath() %>/js/common/jutil.js"></script>
<script src="<%=request.getContextPath() %>/js/easyui/jquery.easyui.min.js"></script>


<script type="text/javascript">
	jQuery(function(){
		
		$('#allbookes').datagrid({
			url:jutil.ctxPath +'/book/query_all_books.action',
			fitColumns:true,
			method:'post',
			loadMsg:'查询中，请等候。。。。',
			striped:true,
			fit:true,
			fitColumns:true,
			rownumbers:true,
			pagination:true,
			pageSize:10,
			pageList:[5,10,20,30,50],
			showFooter:true,
			singleSelect:true,
			queryParams: {
				bname:$("#bname").val()
			},
			columns:[[
			{field:'bookName',title:'书名',width:20,align:'center'},
			{field:'chapter',title:'最新章节',width:30,align:'center',formatter:function(value,row,index){
				if(value){
					return value;
				}else{
					return "抓取中..."
				}
			}},
			{field:'updaeTime',title:'最近更新日期',width:15,align:'center'},
			{field:'webName',title:'站点',width:15,align:'center',formatter:function(value,row,index){
					return '<a href="#" onclick="goToThis(\''+row.url+'\')" title="跳转至该网站">'+row.webName+'</a>';
				}
			},
			{field:'createTime',title:'收录日期',width:10,align:'center'},
			{field:'id',title:'操作',width:10,align:'center',formatter:function(value,row,index){
					if(row.bid){
						return '<a href="#" onclick = cancelOrder(\''+row.id+'\')>取消订阅</a>';
					}else{
						return '<a href="#" onclick = order(\''+row.id+'\')>订阅</a>';
					}
				}
			}
			]]
		})
		
	})
	//打开网页
	function goToThis(url){
		window.open(url); 
	}
	//查询所有符合条件的
	function queryAll(){
		$('#allbookes').datagrid("reload",{
			bname:$("#bname").val()
		})
	}
	//初始化查询
	function initQuery(){
		$("#bname").val("");
		queryAll()
	}
	//订阅
	function order(id){
		jutil.ajax({
			url:"/book/order.action",
			data:{
				id:id
			},
			success:function(data){
				
				if(data.result){
					alert("订阅成功!");
				}
				queryAll();
			}
		})
	}
	//取消订阅
	function cancelOrder(id){
		jutil.ajax({
			url:"/book/cancel_order.action",
			data:{
				id:id
			},
			success:function(data){
				
				queryAll();
			}
		})
	}
</script>
</body>

</html>
